<template>
  <div class="check-editor">
    <div class="check-editor-inner">
      <div class="checkbox" :class="{ checked }" @click="handleChecked"></div>
      <input
        type="text"
        class="editor"
        :value="title"
        @input="handleTextChange"
      />
    </div>
  </div>
</template>

<script setup lang="ts">
import useModelValue from "./composable/useModelValue";
import useModelTitle from "./composable/useModelTitle";
interface IProps {
  modelValue: boolean;
  title: string;
  titleModifiers?: any;
}

const $props = withDefaults(defineProps<IProps>(), {
  modelValue: false,
  title: "",
  titleModifiers: {
    default: () => ({}),
  },
});
const $emits = defineEmits(["update:modelValue", "update:title"]);

const { checked, handleChecked } = useModelValue(
  $props.modelValue,
  (value: boolean) => $emits("update:modelValue", value)
);

const { title, handleTextChange } = useModelTitle(
  $props.title,
  (value: string) => $emits("update:title", value),
  $props.titleModifiers
);
</script>

<style scoped>
.check-editor {
  cursor: pointer;
}
.check-editor-inner {
  display: flex;
  align-items: center;
}
.checkbox {
  width: 15px;
  height: 15px;
  border: 1px solid #dcdfe6;
  box-sizing: border-box;
  border-radius: 3px;
  transition: 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.checkbox:hover,
.checkbox.checked {
  border-color: #409eff;
}
.checkbox.checked::after {
  content: "";
  border-radius: 2px;
  width: 9px;
  height: 9px;
  background: #409eff;
}
.editor {
  border: none;
  outline: none;
  margin-left: 5px;
  border-bottom: 1px solid #dcdfe6;
  font-size: inherit;
}
</style>
